import 'package:safemap/safemap.dart';

import 'vehicle_data_base.dart';
import 'vehicle_realtime_error.dart';
import 'vehicle_realtime_info.dart';
import 'vehicle_realtime_status.dart';

// 所有实时信息类
class VehicleRealtimeAllInfo extends VehicleDataBase {
  // 实时信息
  VehicleRealtimeInfo info = VehicleRealtimeInfo.fromMap({});

  // 实时状态
  VehicleRealtimeStatus status = VehicleRealtimeStatus.fromMap({});

  // 实时错误
  VehicleRealtimeError error = VehicleRealtimeError.fromMap({});

  VehicleRealtimeAllInfo.fromMap(Map<String, dynamic>? data)
      : super.fromMap(data) {
    SafeMap safeMap = SafeMap(data);
    final infoMap = safeMap['info'];
    final statusMap = safeMap['status'];
    final errorMap = safeMap['error'];
    if (infoMap.map is Map<String, dynamic> &&
        statusMap.map is Map<String, dynamic> &&
        errorMap.map is Map<String, dynamic>) {
      info = VehicleRealtimeInfo.fromMap(infoMap.map as Map<String, dynamic>);
      status =
          VehicleRealtimeStatus.fromMap(statusMap.map as Map<String, dynamic>);
      error =
          VehicleRealtimeError.fromMap(errorMap.map as Map<String, dynamic>);
    }
  }
}
